<template>
	<view class="">
		<view class="user-space-head u-f u-f-ac u-f-clumn">
			<view class="user-space-head-bg">
				<image :src="getbgimage" mode="aspectFill" lazy-load @tap="changebgimage"></image>
				{{getbgimage}}
			</view>
			<view class="user-space-head-userinfo u-f u-f-ac u-f-clumn">
				<image :src="userspaceheaddata.userpic" mode="widthFix" lazy-load></image>
				<view class="username-sex u-f u-f-ac user-space-margin">
					<view class="user-space-head-userinfo-title">{{userspaceheaddata.username}}</view>
					<tab-sex :age="userspaceheaddata.age" :sex="userspaceheaddata.sex"></tab-sex>
				</view>
				<view class="user-space-head-btn u-f u-f-ac"  :class="[userspaceheaddata.isguanzhu ? 'active' : '']" @tap="toggleguanzhu">
					<view class="icon iconfont" :class="[userspaceheaddata.isguanzhu ? '' : 'icon-zengjia']"></view>
					<view class="">{{userspaceheaddata.isguanzhu?'已关注':'关注'}}</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
		import tabSex from "../../components/common/tab-sex.vue"
	export default {
		props:{
			userinfo:Object
		},
		components:{
			tabSex
		},
		data(){
			return {
				userspaceheaddata:{}
			}
		},
		beforeMount(){
			this.userspaceheaddata = this.userinfo
		},
		computed:{
			getbgimage(){
				
				return '../../static/bgimg/'+this.userspaceheaddata.bgimageindex+'.jpg'
			}
		},
		methods:{
			// 点击更改背景图片
			changebgimage(){
				this.userinfo.bgimageindex = this.userspaceheaddata.bgimageindex >= 4 ?  1 : ++this.userspaceheaddata.bgimageindex
			},
			// 改变关注状态
			toggleguanzhu(){
				this.userspaceheaddata.isguanzhu = !this.userspaceheaddata.isguanzhu
			}
		}
	}
</script>

<style scoped>
	.user-space-head {
		position:relative;
	}
	.user-space-head-bg{
		width:100%;
		height:480upx;
		overflow: hidden;
	}
	.user-space-head-bg > image {
		vertical-align: middle;
		width:100%;
		height: 100%;
	}
	.user-space-head-userinfo {
		position:absolute;
		top: 150upx;
	}
	.user-space-head-userinfo > image {
		width:150upx;
		height: 150upx;
		border-radius: 50%;
	}
	.user-space-head-userinfo-title {
		font-size : 40upx;
		color:#FFFFFF;
		font-weight: bold;
	}
	.user-space-head-btn {
		padding: 0 10upx;
		border-radius: 10upx;
		background: #FFE933;
	}
	.user-space-head-btn > view{
		font-size: 28upx;
	}
	.user-space-head-btn.active {
		border:1upx solid #999;
		color:#FFFFFF;
		background: transparent;
	}
</style>
